class DataHandler:
    def get_all(self):
        return {
            'KBAR': self.get_kbar_fields_names()
        }

    def get_kbar_fields_names(self):
        fields = []
        names = []
        fields += [
            "($close-$open)/$open",
            "($high-$low)/$open",
            "($close-$open)/($high-$low+1e-12)",
            "($high-Greater($open, $close))/$open",
            "($high-Greater($open, $close))/($high-$low+1e-12)",
            "(Less($open, $close)-$low)/$open",
            "(Less($open, $close)-$low)/($high-$low+1e-12)",
            "(2*$close-$high-$low)/$open",
            "(2*$close-$high-$low)/($high-$low+1e-12)",
        ]

        names += [
            "KMID",
            "KLEN",
            "KMID2",
            "KUP",
            "KUP2",
            "KLOW",
            "KLOW2",
            "KSFT",
            "KSFT2",
        ]

        windows = [5, 10, 20, 30, 60]
        fields += ["Ref($close, %d)/$close" % d for d in windows]
        names += ["ROC%d" % d for d in windows]

        fields += ["Mean($close, %d)/$close" % d for d in windows]
        names += ["MA%d" % d for d in windows]

        fields += ["Std($close, %d)/$close" % d for d in windows]
        names += ["STD%d" % d for d in windows]


        fields += ["Max($high, %d)/$close" % d for d in windows]
        names += ["MAX%d" % d for d in windows]

        fields += ["Min($low, %d)/$close" % d for d in windows]
        names += ["MIN%d" % d for d in windows]

        fields += ["Quantile($close, %d, 0.8)/$close" % d for d in windows]
        names += ["QTLU%d" % d for d in windows]

        fields += ["Quantile($close, %d, 0.2)/$close" % d for d in windows]
        names += ["QTLD%d" % d for d in windows]

        fields += ["Rank($close, %d)" % d for d in windows]
        names += ["RANK%d" % d for d in windows]

        fields += ["($close-Min($low, %d))/(Max($high, %d)-Min($low, %d)+1e-12)" % (d, d, d) for d in windows]
        names += ["RSV%d" % d for d in windows]

        fields += ["IdxMax($high, %d)/%d" % (d, d) for d in windows]
        names += ["IMAX%d" % d for d in windows]

        fields += ["IdxMin($low, %d)/%d" % (d, d) for d in windows]
        names += ["IMIN%d" % d for d in windows]

        fields += ["Ref($volume, %d)/$volume" % d if d != 0 else "$volume/$volume" for d in windows]
        names += ["VOLUME" + str(d) for d in windows]


        

        fields += ["(IdxMax($high, %d)-IdxMin($low, %d))/%d" % (d, d, d) for d in windows]
        names += ["IMXD%d" % d for d in windows]

        fields += ["Corr($close, Log($volume+1), %d)" % d for d in windows]
        names += ["CORR%d" % d for d in windows]

        fields += ["Corr($close/Ref($close,1), Log($volume/Ref($volume, 1)+1), %d)" % d for d in windows]
        names += ["CORD%d" % d for d in windows]

        fields += ["Mean($close>Ref($close, 1), %d)" % d for d in windows]
        names += ["CNTP%d" % d for d in windows]

        fields += ["Mean($close<Ref($close, 1), %d)" % d for d in windows]
        names += ["CNTN%d" % d for d in windows]

        fields += ["Mean($close>Ref($close, 1), %d)-Mean($close<Ref($close, 1), %d)" % (d, d) for d in windows]
        names += ["CNTD%d" % d for d in windows]

        fields += [
            "Sum(Greater($close-Ref($close, 1), 0), %d)/(Sum(Abs($close-Ref($close, 1)), %d)+1e-12)" % (d, d)
            for d in windows
        ]
        names += ["SUMP%d" % d for d in windows]

        fields += [
            "Sum(Greater(Ref($close, 1)-$close, 0), %d)/(Sum(Abs($close-Ref($close, 1)), %d)+1e-12)" % (d, d)
            for d in windows
        ]
        names += ["SUMN%d" % d for d in windows]

        fields += [
            "(Sum(Greater($close-Ref($close, 1), 0), %d)-Sum(Greater(Ref($close, 1)-$close, 0), %d))"
            "/(Sum(Abs($close-Ref($close, 1)), %d)+1e-12)" % (d, d, d)
            for d in windows
        ]
        names += ["SUMD%d" % d for d in windows]

        fields += ["Mean($volume, %d)/($volume+1e-12)" % d for d in windows]
        names += ["VMA%d" % d for d in windows]

        fields += ["Std($volume, %d)/($volume+1e-12)" % d for d in windows]
        names += ["VSTD%d" % d for d in windows]

        fields += [
            "Std(Abs($close/Ref($close, 1)-1)*$volume, %d)/(Mean(Abs($close/Ref($close, 1)-1)*$volume, %d)+1e-12)"
            % (d, d)
            for d in windows
        ]
        names += ["WVMA%d" % d for d in windows]

        fields += [
            "Sum(Greater($volume-Ref($volume, 1), 0), %d)/(Sum(Abs($volume-Ref($volume, 1)), %d)+1e-12)"
            % (d, d)
            for d in windows
        ]
        names += ["VSUMP%d" % d for d in windows]

        fields += [
            "Sum(Greater(Ref($volume, 1)-$volume, 0), %d)/(Sum(Abs($volume-Ref($volume, 1)), %d)+1e-12)"
            % (d, d)
            for d in windows
        ]
        names += ["VSUMN%d" % d for d in windows]

        fields += [
            "(Sum(Greater($volume-Ref($volume, 1), 0), %d)-Sum(Greater(Ref($volume, 1)-$volume, 0), %d))"
            "/(Sum(Abs($volume-Ref($volume, 1)), %d)+1e-12)" % (d, d, d)
            for d in windows
        ]
        names += ["VSUMD%d" % d for d in windows]

        return fields, names